<template>
<div>
    <el-form size="small" :model="inputForm" ref="inputForm" v-loading="loading" :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="施工队长" prop="spreadSuperintendent.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.spreadSuperintendent.id" @getValue='(value) => {inputForm.spreadSuperintendent.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="施工确认附件" prop="constructionConfirmAtionattachment"
                :rules="[
                 ]">
              <el-upload ref="constructionConfirmAtionattachment"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/epc/pmspreadsuperintendent/spreadSuperintendent`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {$window.location.href = (file.response && file.response.url) || file.url}"
                    :on-success="(response, file, fileList) => {
                       inputForm.constructionConfirmAtionattachment = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.constructionConfirmAtionattachment = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="constructionConfirmAtionattachmentArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="施工归档id" prop="roadworkArchive.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择施工归档id"
            labelName = 'proposer'
            labelValue = 'id'
            :value = "inputForm.roadworkArchive.id"
            :limit="1"
            @getValue='(value) => {inputForm.roadworkArchive.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'proposer',
              label: '申请人'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'proposer',
              label: '申请人'
            }
            ]"
            dataListUrl="/epc/pmroadworkarchive/roadworkArchive/list"
            entityBeanName="roadworkArchive"
            queryEntityUrl="/epc/pmroadworkarchive/roadworkArchive/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        constructionConfirmAtionattachmentArra: [],
        inputForm: {
          id: '',
          spreadSuperintendent: {
            id: ''
          },
          constructionConfirmAtionattachment: '',
          roadworkArchive: {
            id: ''
          },
          remarks: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      }
    },
    components: {
      UserSelect,
      GridSelect
    },
    watch: {
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
        this.constructionConfirmAtionattachmentArra = []
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/epc/pmspreadsuperintendent/spreadSuperintendent/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.spreadSuperintendent)
              this.inputForm.constructionConfirmAtionattachment.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.constructionConfirmAtionattachmentArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/pmspreadsuperintendent/spreadSuperintendent/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>